<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('文章列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            关键字：<input type="text" name="keywords"/>
                        </li>

                        <li>
                            <select class="form-control" id="categoryId" name="categoryId">
                                <option value="">请选择</option>
                                <option th:each="category:${categories}" th:value="${category.id}"
                                        th:text="${category.name}"></option>
                            </select>
                        </li>

                        <li>
                            <div class="col-xs-8">
                                <select id="status" class="form-control" name="status">
                                    <option value="">请选择</option>
                                    <option value="1">已发布</option>
                                    <option value="0">草稿</option>
                                </select>
                            </div>
                        </li>

                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="blog:articleCopy:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary btn-edit disabled" onclick="$.operate.edit()"
               shiro:hasPermission="blog:articleCopy:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger btn-del disabled" onclick="$.operate.removeAll()"
               shiro:hasPermission="blog:articleCopy:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="blog:articleCopy:export">
                <i class="fa fa-download"></i> 导出
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" data-mobile-responsive="true"></table>
        </div>
    </div>
</div>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('blog:articleCopy:edit')}]];
    var removeFlag = [[${@permission.hasPermi('blog:articleCopy:remove')}]];
    var prefix = ctx + "blog/articleCopy";

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "文章",
            showExport: true,
            columns: [
                {checkbox: true},
                {
                    field: 'id',
                    title: 'ID',
                    visible: false
                },
                {
                    field: 'title',
                    title: '标题',
                    align: "center"
                }, {
                    field: 'category',
                    title: '分类',
                    align: "center",
                    formatter: function (value) {
                        return value.name;
                    }
                }, {
                    field: 'tags',
                    title: '标签',
                    class: 'table-tags',
                    align: "center",
                    formatter: function (tags) {
                        var tagHtml = '';
                        if (tags) {
                            for (var i = 0, len = tags.length; i < len; i++) {
                                var tag = tags[i];
                                tagHtml += '<a class="btn btn-default btn-xs"> ' + tag.name + '</a> ';
                            }
                        }
                        return tagHtml;
                    }
                }, {
                    field: 'slider',
                    title: '轮播',
                    align: "center",

                    formatter: function (value) {
                        if (value) {
                            return '是'
                        } else {
                            return '否'
                        }
                    }
                }, {
                    field: 'top',
                    title: '置顶',
                    align: "center",
                    formatter: function (value) {
                        if (value) {
                            return '是'
                        } else {
                            return '否'
                        }
                    }
                }, {
                    field: 'recommended',
                    title: '推荐',
                    align: "center",
                    formatter: function (value) {
                        if (value) {
                            return '是'
                        } else {
                            return '否'
                        }
                    }
                }, {
                    field: 'status',
                    title: '状态',
                    align: "center",
                    formatter: function (value) {
                        if (value) {
                            return '已发布'
                        } else {
                            return '草稿'
                        }
                    }
                }, {
                    field: 'lookCount',
                    title: '浏览',
                    align: "center",
                }, {
                    field: 'commentCount',
                    title: '评论',
                    align: "center",
                }, {
                    field: 'loveCount',
                    title: '喜欢',
                    align: "center",
                },
                {
                    field: 'operation',
                    title: '操作',
                    align: "center",
                    class: 'min-width-100',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

</script>
</body>
</html>